#!/usr/bin/python

import sys
from string import *

def find_del(x, max):
	for i in range(max,0,-1):
		if x[i-1] in " .!?;" :
			return i

def find_punctuation(s):
	cnt = 0
	for x in s:
		if x in printable:
			cnt = cnt + 1 
	return cnt

def find_end(x, max):
	if len(x) <= max :
		return len(x)
	end = find_del(x, max)
	num_punc = find_punctuation(x[end:max])
	#print "$"+x[end:]+"$", num_punc
	if end < 1 :
		return max
	if end % 2 :
		if num_punc % 2:
			return max
		else :
			return max-1
	else :
		if num_punc % 2:
			return max-1
		else :
			return max
	
# main function

text = open(sys.argv[1])

if len(sys.argv) > 2 and sys.argv[2] :
	line_width = atoi(sys.argv[2])	
	print line_width
else:
	line_width = 24

#print "Line max length", line_width

prepending = ""
for x in text:
	x = strip(x)
	x = prepending + x
	prepending = ""
	while 1:
		end = find_end(x, line_width)	
#		print "#", x, end
		if strip(x[:end]) == "":
			#print x, "#", end
			break;
		if end == len(x) :
			print strip(x) #, "#", len(strip(x))
			break 
		else :
			if strip(x[:end]) == "" :
				break
			print strip(x[:end]) #, "*", len(strip(x[:end]))
			x = strip(x[end:])
			if len(x) < line_width :
				prepending = x + " "
				x = ""				
			
